<template>
	<view class="page">
		<!-- 地址列表 -->
		<view class="address-list">
			<view class="list"  v-for="(item,index) in lists" :key="index" @click="back(item.id)">
				<view class="name-phone">
					<view class="name">
						<text class="one-omit">{{item.name}}</text>
					</view>
					<view class="phone">
						<text>{{item.phone}}</text>
						<text class="tag" v-if="item.is_default == 1">默认</text>
						<text class="tag blue">公司</text>
					</view>
				</view>
				<view class="address-edit">
					<view class="address">
						<text>{{item.address}}</text>
					</view>
					<view class="edit"  @click.stop="onAddressEdit(1)">
						<text :cid="item.id" class="iconfont icon-edit1"></text>
					</view>
				</view>
			</view>
		</view>
		<!-- 添加地址 -->
		<view class="add-address">
			<view class="btn" @click="onAddressEdit(2)">
				<text>新建收货地址</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lists:[],
				skuId:'',
				price:''
			};
		},
		onLoad(params) {
			var skuIds = params.skuIds
			this.skuId = skuIds
			var totalPrice = params.totalPrice
			this.price = totalPrice
			this.$http.get('user/address', {}).then(res => {
				console.log(res.data.data)
				this.lists = res.data.data
			})
		},
		methods:{
			/**
			 * 编辑地址点击
			 */
			onAddressEdit(type){
				var id = event.target.getAttribute("cid")
				console.log(id)
				uni.navigateTo({
					url: '/pages/AddressEdit/AddressEdit?type=' + type+"&eid="+id,
				})
			},
			back(aid){
				console.log(aid)
				var skuids = this.skuId
				var price  = this.price
				var aid = aid
				uni.navigateTo({
				    	url:'/pages/ConfirmOrder/ConfirmOrder?skuIds='+skuids+'&totalPrice='+price+'&addId='+aid
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'AddressList.scss';
</style>
